<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改停车费')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-park-edit" th:object="${parkRate}">
            <input name="parkId" th:field="*{parkId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">序号：</label>
                <div class="col-sm-8">
                    <input name="num" th:field="*{num}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">项目名称：</label>
                <div class="col-sm-8">
                    <input name="projectName" th:field="*{projectName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">单位名称：</label>
                <div class="col-sm-8">
                    <input name="unitName" th:field="*{unitName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">车牌号：</label>
                <div class="col-sm-8">
                    <input name="licensePlateNum" th:field="*{licensePlateNum}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">单价：</label>
                <div class="col-sm-8">
                    <input name="unitPrice" th:field="*{unitPrice}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">起始日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="createTime" th:value="${#dates.format(parkRate.createTime, 'yyyy-MM-dd')}" class="form-control" placeholder="请填写日期" type="text" >
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">结束日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="updateTime" th:value="${#dates.format(parkRate.updateTime, 'yyyy-MM-dd')}" class="form-control" placeholder="请填写日期" type="text" >
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box " id="chooseStatus1">
                        <label class="radio-box"> <input type="radio"  name="status" value="0" /> 正常 </label>
                        <label class="radio-box"> <input type="radio"  name="status" value="1" /> 到期 </label>
                        <label class="radio-box"> <input type="radio"  name="status" value="2" /> 退租 </label>
                </div>
            </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label ">开票时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="billingTime" th:value="${#dates.format(parkRate.billingTime, 'yyyy-MM-dd')}" class="form-control" placeholder="请填写日期" type="text" >
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">开票金额：</label>
                <div class="col-sm-8">
                    <input name="invoicedAmount" th:field="*{invoicedAmount}" class="form-control" type="text">
                </div>
            </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label ">到账时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="paymentDate" th:value="${#dates.format(parkRate.paymentDate, 'yyyy-MM-dd')}" class="form-control" placeholder="请填写日期" type="text" >
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">到账金额：</label>
                <div class="col-sm-8">
                    <input name="amountReceived" th:field="*{amountReceived}" class="form-control" type="text" >
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">到账状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box is-required" id="chooseStatus2">
                        <label class="radio-box"> <input type="radio"  name="accountStatus" value="0" /> 已到账 </label>
                        <label class="radio-box"> <input type="radio"  name="accountStatus" value="1" /> 未到账 </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" th:field="*{remark}" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "guomao/parkRate";
        /*将后台的值传入前台*/
        var parkRate = [[${parkRate}]];
        $("#form-parkRate-edit").validate({
            focusCleanup: true
        });
        $(function () {
            initStatusChoice1();
            initStatusChoice2();
        })
        /*租户状态回显*/
        function initStatusChoice1(){
            var choice1 = parkRate.status
            console.log("choice1="+choice1)
            $("#chooseStatus1 input").each(function () {
                if($(this).val()==choice1){
                    $(this).parent().addClass("checked")
                    $(this).attr("checked",true)
                }
            });
        }
        function initStatusChoice2(){
            var choice2 = parkRate.accountStatus
            console.log("choice2="+choice2)
            $("#chooseStatus2 input").each(function () {
                if($(this).val()==choice2){
                    $(this).parent().addClass("checked")
                    $(this).attr("checked",true)
                }
            });
        }
        function submitHandler() {
            if ($.validate.form()) {
                edit();
            }
        }
        function edit(){
            var num = $("#num").val();
            var parkId = $("#parkId").val();
            var projectName = $("#projectName").val();
            var unitName=$("#unitName").val();
            var licensePlateNum=$("#licensePlateNum").val();
            var unitPrice=$("#unitPrice").val();
            var createTime=$("#createTime").val();
            var updateTime=$("#updateTime").val();
            var status=$("#status").val();
            var billingTime=$("#billingTime").val();
            var invoicedAmount=$("#invoicedAmount").val();
            var paymentDate=$("#paymentDate").val();
            var amountReceived=$("#amountReceived").val();
            var accountStatus=$("#accountStatus").val();
            var remark = $("#remark").val();

            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "guomao/parkRate/edit",
                data : {
                    "num":num,
                    "parkId":parkId,
                    "projectName":projectName,
                    "unitName": unitName,
                    "licensePlateNum": licensePlateNum,
                    "unitPrice": unitPrice,
                    "createTime": createTime,
                    "updateTime": updateTime,
                    "status": status,
                    "billingTime": billingTime,
                    "invoicedAmount": invoicedAmount,
                    "paymentDate": paymentDate,
                    "amountReceived": amountReceived,
                    "accountStatus": accountStatus,
                    "remark": remark
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误.");
                },
                success : function(data) {
                    $.operate.successCallback(data);
                }
            });
        }
        $("#form-park-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-park-edit').serialize());
            }
        }
        $("input[name='createTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='updateTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        $("input[name='billingTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='paymentDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

    </script>
</body>
</html>